<template>
  <div class="app-container">
    <div class="filter-container">
      车辆VIN号：<el-input v-model="listQuery.vin" placeholder="请输入车辆VIN号" style="width: 200px;" class="filter-item" />
      路由点：<el-input v-model="listQuery.departure" placeholder="请输入路由点" style="width: 200px;" class="filter-item" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
      <el-button v-waves class="filter-item" type="info" icon="el-icon-refresh" @click="handleReset">
        重置
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="车辆WIN号" prop="vin" align="center" width="300px">
        <template slot-scope="scope">
          <span>{{ scope.row.vin }}</span>
        </template>
      </el-table-column>
      <el-table-column label="路由点" prop="departure" align="center" width="300px">
        <template slot-scope="scope">
          <span>{{ scope.row.departure }}</span>
        </template>
      </el-table-column>
      <el-table-column label="目的地" prop="destination" align="center" width="300px">
        <template slot-scope="scope">
          <span>{{ scope.row.destination }}</span>
        </template>
      </el-table-column>
      <el-table-column label="时间" prop="createTime" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>
import { fetchList } from '@/api/bdc/route-log'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'RouteLog',
  directives: { waves },
  components: { Pagination },
  data() {
    return {
      // 查询模块
      listQuery: {
        page: 1,
        limit: 10,
        vin: undefined,
        departure: undefined
      },
      // 表格显示
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(res => {
        if (res.code == 200) {
          this.list = res.data.list
          this.total = res.data.total
        } else {
          this.$message.error('服务器内部错误！');
        }
        this.listLoading = false
      })
    },
    // 查询
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    // 重置
    handleReset() {
      this.listQuery = {
        page: 1,
        limit: 20,
        vin: undefined,
        departure: undefined
      }
    },
  }
}
</script>